package com.tuanzi.loan.business.service.sms.el;

import java.util.List;

import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MatchRuleExpressionEvaluatorImpl implements ExpressionEvaluator<List<String>> {

	private static final long serialVersionUID = 1L;

	private final EvaluationContextBuilder evaluationContextBuilder;

	public MatchRuleExpressionEvaluatorImpl(EvaluationContextBuilder evaluationContextBuilder) {
		this.evaluationContextBuilder = evaluationContextBuilder;
	}

	@Override
	public List<String> evaluate(String expression) {

		ExpressionParser parser = new SpelExpressionParser();
		Expression exp = parser.parseExpression(expression);

		Object value = exp.getValue(evaluationContextBuilder.buildEvaluationContext());
		log.info("expression : {} =  result : {}", expression, value);

		return (List<String>) value;
	}

}
